﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
public partial class Main_Inventory_PurchaseReceived_PurchaseReceiveInternationalDisplay : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string POID = "";
    string transferedid = "";
    string supplier = "";
    string taxgroup = "";
    string trnid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Request.QueryString["POID"] != null && Request.QueryString["transferedid"] != null)
        {
            POID = Request.QueryString["POID"].ToString();
            transferedid = Request.QueryString["transferedid"].ToString();
            trnid = Request.QueryString["trnid"].ToString();
        }
        if (!IsPostBack)
        {
            BindPurchaseReceivd();
            BindPurchaseReceivedItems();            
        }
    }
    protected void BindPurchaseReceivd()
    {
        SqlParameter[] parm = { new SqlParameter("@TRNID", trnid) };
        DataTable dt = DU.getdatausingprocedure("usp_IVR_DisplayInternationalPurchaseReceived", parm);
        if (dt.Rows.Count > 0)
        {
            //Main of the International
            lblPONumber.Text = dt.Rows[0]["pono"].ToString();
            lblSupplier.Text = dt.Rows[0]["Lname"].ToString();
            lblvouno.Text = dt.Rows[0]["voucherno"].ToString();
            lblinvno.Text = dt.Rows[0]["invoiceno"].ToString();
            lblmodeofpay.Text = dt.Rows[0]["Modeofpayment"].ToString();
            lblbilref.Text = dt.Rows[0]["bill"].ToString();
            lbldate.Text = dt.Rows[0]["TRNDATE"].ToString();
            lbltaxgroup.Text = dt.Rows[0]["MAINCLASSNAME"].ToString();
            lblmodeofdelivery.Text = dt.Rows[0]["modeofdelivery"].ToString();
            lbldeliverydate.Text = dt.Rows[0]["deliverydate"].ToString();
            lbldocno.Text = dt.Rows[0]["documentnum"].ToString();
            lbltransportname.Text = dt.Rows[0]["vehiclenum"].ToString();
            lblvehicleno.Text = dt.Rows[0]["transportname"].ToString();
            lblpreparedby.Text = dt.Rows[0]["preparedby"].ToString();
            lblcheckedby.Text = dt.Rows[0]["checkedby"].ToString();
            lblauthorizedby.Text = dt.Rows[0]["AUTHRSDSIGNAT"].ToString();
            lblnarration.Text = dt.Rows[0]["narration"].ToString();
            lblremarks.Text = dt.Rows[0]["remarks"].ToString();
            LblCurrency.Text = dt.Rows[0]["Currency"].ToString();
            lblCurrencyUImport.Text ="("+ dt.Rows[0]["Currency"].ToString()+")";
            lblCurrencyImport.Text = "(" + dt.Rows[0]["Currency"].ToString() + ")";
            lblFolioNo.Text = dt.Rows[0]["Foliono"].ToString();
            lblExchangerate.Text = dt.Rows[0]["ExchangeRate"].ToString();
            lblInvoicevalue.Text = Convert.ToDouble(dt.Rows[0]["TotalInvoiceAmt"].ToString()).ToString("N2");
            lblPurchaseReceDate.Text = Convert.ToDateTime(dt.Rows[0]["PurchaseRecDate"].ToString()).ToShortDateString();

            //For The Total Of the InterNational
            lbltotalitemqty.Text = Convert.ToDouble(dt.Rows[0]["TOTALITEMQTY"].ToString()).ToString("N2");
            lbltotallandedcost.Text = Convert.ToDouble(dt.Rows[0]["ITEMTOTAL"].ToString()).ToString("N2");
            lbltoalinventorycost.Text = Convert.ToDouble(dt.Rows[0]["TAXABLEAMT"].ToString()).ToString("N5");
            lblclearingfreight.Text = Convert.ToDouble(dt.Rows[0]["FREIGHT"].ToString()).ToString("N5");
            lblpackingcharge.Text = Convert.ToDouble(dt.Rows[0]["PACKAGING"].ToString()).ToString("N5");
            lblInsurance.Text = Convert.ToDouble(dt.Rows[0]["INSURANCE"].ToString()).ToString("N5");
            lblOtherCharges.Text = Convert.ToDouble(dt.Rows[0]["OTHERCHARGE"].ToString()).ToString("N5");
            lblgrandtotal.Text = Convert.ToDouble(dt.Rows[0]["GrandTotal"].ToString()).ToString("N2");            

            lblbillingaddress.Text=dt.Rows[0]["BILLINGADDRESS"].ToString().Replace("<br />","\r");
            lbldeliveryaddress.Text = dt.Rows[0]["DELIVERYADDRESS"].ToString().Replace("<br />", "\r");

            lblbcd.Text=Convert.ToDouble(dt.Rows[0]["BCD"].ToString()).ToString("N5");            
            lblcvd.Text=Convert.ToDouble(dt.Rows[0]["CVD"].ToString()).ToString("N5");            
            lbladdlduty.Text=Convert.ToDouble(dt.Rows[0]["ADDLDUTY"].ToString()).ToString("N5");            
            lblheducessoncvd.Text=Convert.ToDouble(dt.Rows[0]["SHECESSONCVD"].ToString()).ToString("N5");            
            lbleducessoncvd.Text=Convert.ToDouble(dt.Rows[0]["ECESSONCVD"].ToString()).ToString("N5");            
            lblcustomeducess.Text=Convert.ToDouble(dt.Rows[0]["CUSTOMEDUCESS"].ToString()).ToString("N5");            
            lblhcustomeducess.Text=Convert.ToDouble(dt.Rows[0]["SHCUSTOMEDUCESS"].ToString()).ToString("N5");            
            lbldutypayable.Text=Convert.ToDouble(dt.Rows[0]["DUTYPAYABLE"].ToString()).ToString("N5");            
            lblassessvalue.Text=Convert.ToDouble(dt.Rows[0]["AssesValue"].ToString()).ToString("N5"); 
        }
    }
    protected void BindPurchaseReceivedItems()
    {
        SqlParameter[] parareceived = { 
                                       new SqlParameter("@TRNID",trnid)
                                      };
        DataTable dtreceived = DU.getdatausingprocedure("usp_ivr_purchaseReceivedInternational", parareceived);
        if (dtreceived.Rows.Count > 0)
        {
            for (int i = 0; i < dtreceived.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                Label lblitems = new Label();
                lblitems.Text = dtreceived.Rows[i]["Items"].ToString();
                lblitems.Width = 150;
                cell1.Style.Add("border-right", "1px solid #818181");
                cell1.Style.Add("border-bottom", "1px solid #818181");
                cell1.Controls.Add(lblitems);

                HtmlTableCell cell18 = new HtmlTableCell();
                Label lblUnit = new Label();
                lblUnit.Text = dtreceived.Rows[i]["Unit"].ToString();
                cell18.Style.Add("border-right", "1px solid #818181");
                cell18.Style.Add("border-bottom", "1px solid #818181");
                cell18.Controls.Add(lblUnit);

                HtmlTableCell cell3 = new HtmlTableCell();
                Label lblrecqty = new Label();
                lblrecqty.Text = Convert.ToDouble(dtreceived.Rows[i]["UNITPRICE"].ToString()).ToString("N2");
                cell3.Style.Add("border-right", "1px solid #818181");
                cell3.Style.Add("border-bottom", "1px solid #818181");
                cell3.Style.Add("text-align", "right");
                cell3.Controls.Add(lblrecqty);

                HtmlTableCell cell4 = new HtmlTableCell();
                Label lblrate = new Label();
                lblrate.Text = Convert.ToDouble(dtreceived.Rows[i]["QTY"].ToString()).ToString("N0");
                cell4.Style.Add("border-right", "1px solid #818181");
                cell4.Style.Add("border-bottom", "1px solid #818181");
                cell4.Style.Add("text-align", "right");
                cell4.Controls.Add(lblrate);

                HtmlTableCell cell5 = new HtmlTableCell();
                Label lblEXTENDEDVALUE = new Label();
                if (dtreceived.Rows[i]["EXTENDEDVALUE"].ToString() != "")
                {
                    lblEXTENDEDVALUE.Text = Convert.ToDouble(dtreceived.Rows[i]["EXTENDEDVALUE"].ToString()).ToString("N2");
                }
                cell5.Style.Add("border-right", "1px solid #818181");
                cell5.Style.Add("border-bottom", "1px solid #818181");
                cell5.Style.Add("text-align", "right");
                cell5.Controls.Add(lblEXTENDEDVALUE);

                HtmlTableCell cell6 = new HtmlTableCell();
                Label lblUNITPRICEINR = new Label();
                if (dtreceived.Rows[i]["UNITPRICEINR"].ToString() != "")
                {
                    lblUNITPRICEINR.Text = Convert.ToDouble(dtreceived.Rows[i]["UNITPRICEINR"].ToString()).ToString("N2");
                }
                cell6.Style.Add("border-right", "1px solid #818181");
                cell6.Style.Add("border-bottom", "1px solid #818181");
                cell6.Style.Add("text-align", "right");
                cell6.Controls.Add(lblUNITPRICEINR);

                HtmlTableCell cell7 = new HtmlTableCell();
                Label lblINVOICEVALUE = new Label();
                if (dtreceived.Rows[i]["INVOICEVALUE"].ToString() != "")
                {
                    lblINVOICEVALUE.Text = Convert.ToDouble(dtreceived.Rows[i]["INVOICEVALUE"].ToString()).ToString("N2");
                }
                cell7.Style.Add("border-right", "1px solid #818181");
                cell7.Style.Add("text-align", "right");
                cell7.Style.Add("border-bottom", "1px solid #818181");
                cell7.Controls.Add(lblINVOICEVALUE);

                HtmlTableCell cell8 = new HtmlTableCell();
                Label lblamtpayble = new Label();
                lblamtpayble.Text = Convert.ToDouble(dtreceived.Rows[i]["ACCESSVALUE"].ToString()).ToString("N2");
                cell8.Style.Add("text-align", "right");
                cell8.Style.Add("border-right", "1px solid #818181");
                cell8.Style.Add("border-bottom", "1px solid #818181");
                cell8.Controls.Add(lblamtpayble);

                HtmlTableCell cell9 = new HtmlTableCell();
                Label lblpurchaseledger = new Label();
                cell9.Style.Add("border-right", "1px solid #818181");
                lblpurchaseledger.Text = dtreceived.Rows[i]["CVD"].ToString();
                cell9.Style.Add("border-bottom", "1px solid #818181");
                cell9.Controls.Add(lblpurchaseledger);

                HtmlTableCell cell10 = new HtmlTableCell();
                Label lbltaxledger = new Label();
                lbltaxledger.Text = dtreceived.Rows[i]["educessoncvd"].ToString();
                cell10.Style.Add("border-right", "1px solid #818181");
                cell10.Style.Add("border-bottom", "1px solid #818181");
                cell10.Controls.Add(lbltaxledger);

                HtmlTableCell cell11 = new HtmlTableCell();
                Label lblHeducessCVD = new Label();
                lblHeducessCVD.Text = dtreceived.Rows[i]["heducessoncvd"].ToString();
                cell11.Style.Add("border-right", "1px solid #818181");
                cell11.Style.Add("border-bottom", "1px solid #818181");
                cell11.Controls.Add(lblHeducessCVD);

                HtmlTableCell cell12 = new HtmlTableCell();
                Label lbltotalduty = new Label();
                lbltotalduty.Text = dtreceived.Rows[i]["totalduty"].ToString();
                cell12.Style.Add("border-right", "1px solid #818181");
                cell12.Style.Add("border-bottom", "1px solid #818181");
                cell12.Controls.Add(lbltotalduty);

                HtmlTableCell cell13 = new HtmlTableCell();
                Label lblcustomeducational = new Label();
                lblcustomeducational.Text = dtreceived.Rows[i]["customeducational"].ToString();
                cell13.Style.Add("border-right", "1px solid #818181");
                cell13.Style.Add("border-bottom", "1px solid #818181");
                cell13.Controls.Add(lblcustomeducational);

                HtmlTableCell cell14 = new HtmlTableCell();
                Label lblcustomhedu = new Label();
                lblcustomhedu.Text = dtreceived.Rows[i]["customhedu"].ToString();
                cell14.Style.Add("border-right", "1px solid #818181");
                cell14.Style.Add("border-bottom", "1px solid #818181");
                cell14.Controls.Add(lblcustomhedu);

                HtmlTableCell cell15 = new HtmlTableCell();
                Label lbladdduty = new Label();
                lbladdduty.Text = dtreceived.Rows[i]["addduty"].ToString();
                cell15.Style.Add("border-right", "1px solid #818181");
                cell15.Style.Add("border-bottom", "1px solid #818181");
                cell15.Controls.Add(lbladdduty);

                HtmlTableCell cell16 = new HtmlTableCell();
                Label lblgrandtotalduty = new Label();
                lblgrandtotalduty.Text = dtreceived.Rows[i]["grandtotalduty"].ToString();
                cell16.Style.Add("border-right", "1px solid #818181");
                cell16.Style.Add("border-bottom", "1px solid #818181");
                cell16.Controls.Add(lblgrandtotalduty);

                HtmlTableCell cell17 = new HtmlTableCell();
                Label lblfreight = new Label();
                lblfreight.Text = dtreceived.Rows[i]["freight"].ToString();
                cell17.Style.Add("border-right", "1px solid #818181");
                cell17.Style.Add("border-bottom", "1px solid #818181");
                cell17.Controls.Add(lblfreight);

                HtmlTableCell cell20 = new HtmlTableCell();
                Label lbltotallandedCost = new Label();
                lbltotallandedCost.Text = dtreceived.Rows[i]["totallandedCost"].ToString();
                cell20.Style.Add("border-right", "1px solid #818181");
                cell20.Style.Add("border-bottom", "1px solid #818181");
                cell20.Controls.Add(lbltotallandedCost);

                //HtmlTableCell cell21 = new HtmlTableCell();
                //Label lblTotalinventcost = new Label();
                //lblTotalinventcost.Text = dtreceived.Rows[i]["Totalinventcost"].ToString();
                //cell21.Style.Add("border-right", "1px solid #818181");
                //cell21.Style.Add("border-bottom", "1px solid #818181");
                //cell21.Controls.Add(lblTotalinventcost);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell18);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);
                row1.Cells.Add(cell7);
                row1.Cells.Add(cell8);
                row1.Cells.Add(cell9);
                row1.Cells.Add(cell10);
                row1.Cells.Add(cell11);
                row1.Cells.Add(cell12);
                row1.Cells.Add(cell13);
                row1.Cells.Add(cell14);
                row1.Cells.Add(cell15);
                row1.Cells.Add(cell16);
                row1.Cells.Add(cell17);               
                row1.Cells.Add(cell20);
                //row1.Cells.Add(cell21);
                tbl_purReceived.Rows.Add(row1);
                //lbltotalitemqty.Text = Convert.ToDouble(dtreceived.Compute("sum(itmqty)", "").ToString()).ToString("N2");
                //lblposttaxtotal.Text = Convert.ToDouble(dtreceived.Compute("sum(itmamt)", "").ToString()).ToString("N2");
            }
        }
    }   
}